package com.turing.usdtpay.mvp.dialog;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.turing.usdtpay.R;
import com.turing.usdtpay.base.BaseDialog;
import com.turing.usdtpay.common.StateContants;
import com.turing.usdtpay.utils.QRCodeUtil;
import com.turing.usdtpay.utils.ScreenUtils;

/**
 * @作者：JAY
 * @创建时间：2019/10/19 17:03
 * @描述：
 **/
public class QRDialog extends BaseDialog<QRDialog> {
    private ImageView mCode;
    private String mURL = "";
    public QRDialog(Context context) {
        super(context);
    }

    public QRDialog(Context context, boolean isPopupStyle) {
        super(context, isPopupStyle);
    }

    public QRDialog(Context context, int theme) {
        super(context, theme);
    }

    @Override
    public View onCreateView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_qr_code, null);
        mCode = (ImageView) view.findViewById(R.id.iv_code);
        return view;
    }

    @Override
    public void setUiBeforeShow() {
        setCancelable(true);
        setCanceledOnTouchOutside(true);
    }

    @Override
    public void onClick(View v) {

    }

    public void setCode(String url){
        mURL = url;
    }

    public void showQRCode() {
        Picasso.get().load(mURL).into(mCode);
    }

    public void showQRCodeByBitmap(Bitmap bitmap){
        mCode.setImageBitmap(bitmap);
    }

    @Override
    public void show() {
        super.show();
        int mOrientation = mActivity.getResources().getConfiguration().orientation;
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        if (Configuration.ORIENTATION_PORTRAIT == mOrientation) {
            layoutParams.width = (int) (ScreenUtils.getScreenWidth(mContext) * StateContants.FLOW_WINDOW_PORTRAIT_WIDTH_SCALE);
            layoutParams.height = (int) (ScreenUtils.getScreenHeight(mContext) * StateContants.FLOW_WINDOW_PORTRAIT_HEIGHT_SCALE);
        }else {
            layoutParams.width = (int) (ScreenUtils.getScreenWidth(mContext)* StateContants.FLOW_WINDOW_PORTRAIT_WIDTH_SCALE);
//            layoutParams.height = (int) (ScreenUtils.getScreenHeight(mContext) * SDKConstants.FLOW_WINDOW_LANDSCAPE_HEIGHT_SCALE);
        }
        getWindow().setAttributes(layoutParams);
    }


}
